package com.zzyl.controller.security;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zzyl.base.PageBean;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.PostDto;
import com.zzyl.service.PostService;
import com.zzyl.vo.PostVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 岗位前端控制器
 */
@Slf4j
@RestController
@RequestMapping("/post")
@RequiredArgsConstructor
public class PostController {
	
	private final PostService postService;
	
	/***
	 *  多条件查询岗位分页列表
	 * @param postDto 岗位Vo查询条件
	 * @param pageNum 页码
	 * @param pageSize 每页条数
	 * @return: PageResponse<PostVo>
	 */
	@PostMapping("/page/{pageNum}/{pageSize}")
	@ApiOperation(value = "岗位分页", notes = "岗位分页")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "postDto", value = "岗位DTO对象", required = true, dataType = "PostDto"),
			@ApiImplicitParam(paramType = "path", name = "pageNum", value = "页码", example = "1", dataType = "Integer"),
			@ApiImplicitParam(paramType = "path", name = "pageSize", value = "每页条数", example = "10", dataType = "Integer")
	})
	@ApiOperationSupport(includeParameters = {"postDto.deptNo", "postDto.dataState", "postDto.postName"})
	public ResponseResult<PageBean<PostVo>> findPostVoPageResponse(
			@RequestBody PostDto postDto,
			@PathVariable("pageNum") int pageNum,
			@PathVariable("pageSize") int pageSize) {
		PageBean<PostVo> pageResponse = postService.findPostPage(postDto, pageNum, pageSize);
		return ResponseResult.success(pageResponse);
	}
	
	/**
	 * 保存岗位
	 * @param postDto 岗位DTO对象
	 * @return PostDto
	 */
	@PutMapping
	@ApiOperation(value = "岗位添加", notes = "岗位添加")
	@ApiImplicitParam(name = "postDto", value = "岗位DTO对象", required = true, dataType = "PostDto")
	@ApiOperationSupport(includeParameters = {"postDto.deptNo", "postDto.dataState", "postDto.postName", "postDto.remark"})
	public ResponseResult<PostVo> createPost(@RequestBody PostDto postDto) {
		PostVo postVoResult = postService.createPost(postDto);
		return ResponseResult.success(postVoResult);
	}
	
	/**
	 * 修改岗位
	 * @param postDto 岗位DTO对象
	 * @return Boolean 是否修改成功
	 */
	@PatchMapping
	@ApiOperation(value = "岗位修改", notes = "岗位修改")
	@ApiImplicitParam(name = "postDto", value = "岗位DTO对象", required = true, dataType = "PostDto")
	@ApiOperationSupport(includeParameters = {
			"postDto.deptNo",
			"postDto.dataState",
			"postDto.postName",
			"postDto.remark",
			"postDto.id"})
	public ResponseResult updatePost(@RequestBody PostDto postDto) {
		postService.updatePost(postDto);
		return ResponseResult.success();
	}
	
	@PatchMapping("/is_enable")
	@ApiOperation(value = "启用-禁用", notes = "启用-禁用")
	@ApiImplicitParam(name = "postDto", value = "岗位DTO对象", required = true, dataType = "PostDto")
	@ApiOperationSupport(includeParameters = {"postDto.dataState", "postDto.id"})
	public ResponseResult isEnable(@RequestBody PostDto postDto) {
		postService.isEnable(postDto);
		return ResponseResult.success();
	}
	
	/**
	 * 删除岗位
	 */
	@ApiOperation("删除岗位")
	@DeleteMapping("/{postId}")
	public ResponseResult remove(@PathVariable String postId) {
		postService.deletePostById(postId);
		return ResponseResult.success();
	}
	
	/***
	 *  多条件查询岗位列表
	 * @param postDto 岗位DTO对象
	 * @return List<PostVo>
	 */
	@PostMapping("/list")
	@ApiOperation(value = "岗位列表", notes = "岗位列表")
	@ApiImplicitParam(name = "postDto", value = "岗位DTO对象", required = true, dataType = "PostDto")
	@ApiOperationSupport(includeParameters = {"postDto.deptNo"})
	public ResponseResult<List<PostVo>> postList(@RequestBody PostDto postDto) {
		List<PostVo> postVoList = postService.findPostList(postDto);
		return ResponseResult.success(postVoList);
	}
	
	
}
